# NodeJS Update Script

> Tested on: Debian 8.3
> Bash: 4.3
> ZSH: 5.0.7

Note: if `npm` is installed, you can simply install the newest stable version of NodeJS with:
```
su -c "npm install -g n" root
su -c "n stable" root
```

## Table of Contents
1. [Dependencies](#dependencies)
	* [Script](#script)
	* [NodeJS](#nodejs)
2. [Usage](#usage)
	* [Version-Argument](#version)
	* [Builddir-Argument](#build-dir)
	* [Clean-Argument](#clean)
3. [Miniscript](#miniscript)
4. [How it operates](#how-it-operates)


## Dependencies

### Script
* wget
* tar
* git

### NodeJS
* gcc 		[>= 4.8]
* g++ 		[>= 4.8]
* clang 	[>= 3.4]
* clang++ 	[>= 3.4]
* python 	[= 2.7]
* GNU make 	[>= 3.8.1]
See: [NodeJS-Github](https://github.com/nodejs/node#build)

## Usage
Run with any Shell (tested with bash and zsh).
```
update-nodejs.run "VERSION" "BUILD-DIR" "CLEAN"
```

If no argument is used, a help is shown.

### VERSION
Can bei either `git` or [any version-number](https://github.com/nodejs/node/releases).
**NON-OPTIONAL** argument!
```
update-nodejs.run 5.5.0
```

### BUILD-DIR
Any directory your user has write-rights to.
specifies the PARENT-folder:
BUILD-DIR: `~/` means, that it will build in `~/node-VERSION`.
*defaults to `~/build/nodejs`
**NON-OPTIONAL** argument if the `CLEAN` argument is used as well!
```
update-nodejs.run "VERSION" ~/my_packages
```

### CLEAN
Can either be `YES` (in caps) or anything other than that.
specifies, if the *actual* build-directory will be deleted after installing.
If set to `YES`, it will delete `BUILD-DIR/node-VERSION`. `BUILD-DIR` will not be deleted.
**OPTIONAL** argument!
```
update-nodejs.run "VERSION" "BUILD-DIR" YES
```


## Miniscript
Minimal version of the original script.
```
update-nodejs-miniscript.run "VERSION"
```

The Miniscript will **always** use `~/TMP_NODE_BUILDDIR` as building-directory.
The building-directory will be deleted after installing.
**Use the Miniscript with care!**

## How it operates
1. Downloads specified NodeJS version to `BUILD-DIR` (either via `git clone` or `wget`). [See here](https://notabug.org/jayvii/Scripts/src/master/NodeJS-updater/update-nodejs.run#L68-L110)
	* If `node-git` already exists, `git pull` will be used instead. [See here](https://notabug.org/jayvii/Scripts/src/master/NodeJS-updater/update-nodejs.run#L72-L81)
	* If a folder of the same release-version already exists, `wget` will not download anything. [See here](https://notabug.org/jayvii/Scripts/src/master/NodeJS-updater/update-nodejs.run#L92-L99)
2. Builds and installs NodeJS with `./configure`, `make` and (as ROOT) `make install`. [See here](https://notabug.org/jayvii/Scripts/src/master/NodeJS-updater/update-nodejs.run#L112-L130)
3. Links `/usr/local/bin/node` to `/usr/bin/node` (some applications seem to prefer the later). [See here](https://notabug.org/jayvii/Scripts/src/master/NodeJS-updater/update-nodejs.run#L141-L154)
